/**
 * @file ai_message_router.h
 * @brief Central message router for AI communication system
 */

#ifndef AI_MESSAGE_ROUTER_H
#define AI_MESSAGE_ROUTER_H

#include "ai_communication_protocol.h"
#include "human_ai_terminal.h"
#include "ai_computer_terminal.h"
#include <vector>
#include <map>
#include <queue>
#include <functional>

class AIMessageRouter
{
public:
    static AIMessageRouter& GetInstance();
    
    bool Initialize();
    bool SendMessage(const AIMessage& message);
    bool ReceiveMessage(AIMessage& message, TerminalType receiver);
    void RouteMessage(const AIMessage& message);
    void RegisterMessageHandler(TerminalType terminal, std::function<void(const AIMessage&)> handler);
    wxString GetSystemStatus() const;

private:
    AIMessageRouter();
    
    HumanAITerminal m_humanAITerminal;
    AIComputerTerminal m_aiComputerTerminal;
    
    std::map<TerminalType, std::queue<AIMessage>> m_messageQueues;
    std::map<TerminalType, std::function<void(const AIMessage&)>> m_messageHandlers;
    
    void HandleHumanToAIMessage(const AIMessage& message);
    void HandleAIToComputerMessage(const AIMessage& message);
    void HandleAIToHumanMessage(const AIMessage& message);
    void HandleComputerToAIMessage(const AIMessage& message);
    bool ValidateMessage(const AIMessage& message);
};

#endif
